package com.lihepeng.leecode.frequency.tree;

import java.util.ArrayList;
import java.util.List;

/**
 * 前序 遍历
 * review
 * 2022年5月10日
 */
public class PreOrderTravel {
    /**
     * 前序遍历
     */
    public List<Integer> preOrderTravel(TreeNode treeNode){
        List<Integer> result = new ArrayList<>();
        if (treeNode ==null) {
            return result;
        }
        preOrderTravel(treeNode,result);
        int [] arrs = new int[result.size()];
        for (int i =0;i<result.size();i++) {
            arrs[i] = result.get(i);
        }
        return result;
    }
    private void preOrderTravel(TreeNode treeNode,List<Integer> result){
        if (treeNode ==null) {
            return;
        }
        result.add(treeNode.val);
        preOrderTravel(treeNode.left);
        preOrderTravel(treeNode.right);

    }
}
